home *** CD-ROM | disk | FTP | other *** search
- Path: news.iag.net!news
- From: jatmon@iag.net (John R Buchan)
- Newsgroups: comp.lang.c
- Subject: Re: Array of pointers to a tree structure ?
- Date: 11 Jan 1996 16:57:19 GMT
- Organization: Internet Access Group, Orlando, Florida
- Distribution: world
- Message-ID: <4d3fhf$9fl@news.iag.net>
- References: <4d067t$9lc@hermes.fundp.ac.be> <nxRvQDA1468wEw$$@harden.demon.co.uk>
- NNTP-Posting-Host: pm3-orl4.iag.net
- X-Newsreader: WinVN 0.99.7
-
- In article <nxRvQDA1468wEw$$@harden.demon.co.uk>, mark@harden.demon.co.uk
- says...
- >
- >In article <4d067t$9lc@hermes.fundp.ac.be>, Francisco Melo Ledermann
- <snip>
- >>/* BOXES STRUCTURE FOR THE CONSTRUCTION OF A TREE */
- >>
- >>struct boxes {
- >> int number;
- >> struct boxes *pointer_1;
- >> struct boxes *pointer_2;
- >> struct boxes *pointer_3;
- >> }
- >>
- >>/* ARRAY OF POINTERS TO BOXES STRUCTURE FOR MANAGE */
- >>/* SOME BRANCHES OF THE TREE */
- >>
- >>struct boxes array_pointers [15];
- >
- >Should be "strut boxes *array_pointers [15];" otherwise you are defining
- >an array of structures.
- <snip>
- > *array_pointers [3]->number = 13;
-
- The array element '[]' and pointer to structure member '->' operators have
- a higher precedence than the dereference '*'. So this is equivalent to:
-
- *(array_pointers [3]->number) = 13;
-
- Which generates an illegal dereference. I suspect that you intended:
-
- (*array_pointers [3])->number = 13;
-
- But this won't work either. It gets and dereferences the third element
- in the pointer array. You are now dealing with a struct, not a pointer.
- So you should use '.', not '->'. Try:
-
- (*array_pointers [3]).number = 13;
- or
- array_pointers [3]->number = 13;
-
- >
- >To set "pointer_1" in the structure pointed to be array element 3 to
- >that pointed to by array element 4 you would :-
- >
- > *array_pointers [3]->pointer_1 = array_pointers [4];
-
- Hmm... I forgot that method in my examples. However make it:
-
- array_pointers [3]->pointer_1 = array_pointers [4];
- or
- (*array_pointers [3]).pointer_1 = array_pointers [4];
-
-
- --
- John R Buchan -:|:- Looking for that elusive FAQ? ftp to:
- jatmon@mail.iag.net -:|:- rtfm.mit.edu /pub/usenet-by-group/....
-
-